package high.concurrent.strategy;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 创建短链码分片的库位前缀
 */
public class CreateCodePrefixDbConfig {

    /**
     * 存储库前缀集合
     */
    private static List<String> shortLinkDbPrefixList = new ArrayList<>();

    private static Random random = new Random();
    /**
     * 向集合中添加现有的库前缀，有3个库分别是0，1，a，所以集合就暂时存0,1,a
     */
    static {
        shortLinkDbPrefixList.add("0");
        shortLinkDbPrefixList.add("1");
        shortLinkDbPrefixList.add("2");
        shortLinkDbPrefixList.add("3");
        shortLinkDbPrefixList.add("4");
        shortLinkDbPrefixList.add("5");
        shortLinkDbPrefixList.add("6");
        shortLinkDbPrefixList.add("7");
        shortLinkDbPrefixList.add("8");
        shortLinkDbPrefixList.add("9");
        shortLinkDbPrefixList.add("a");
        shortLinkDbPrefixList.add("b");
        shortLinkDbPrefixList.add("c");
        shortLinkDbPrefixList.add("d");
        shortLinkDbPrefixList.add("e");
    }

    public static String getShortLinkDbPrefix(){
        int prefix = random.nextInt(shortLinkDbPrefixList.size());
        return shortLinkDbPrefixList.get(prefix);
    }

}
